#include ".\displayobject.h"

CDisplayObject::CDisplayObject(void)
{
	m_ObjectType = OT_Display;
	m_ptScreenPos.x = 0;
	m_ptScreenPos.y = 0;
	m_bVisible = TRUE;
	m_bShowFrame = TRUE;
	m_nWidth = 0;
	m_nHeight = 0;
	m_nAlpha = 255;
}

CDisplayObject::~CDisplayObject(void)
{

}

void CDisplayObject::AddRef()
{
	return;
}

void CDisplayObject::SetPos(POINT ptPos)
{
	m_ptScreenPos = ptPos;	
}

void CDisplayObject::SetPos(int x,int y)
{
	m_ptScreenPos.x = x;
	m_ptScreenPos.y = y;
}

POINT CDisplayObject::GetPos()
{
	return m_ptScreenPos;
}

void CDisplayObject::SetVisible(BOOL bVisible)
{
	m_bVisible = bVisible;
}

BOOL CDisplayObject::GetVisible()
{
	return m_bVisible;
}

void CDisplayObject::SetWidthAndHeight(UINT nWidth,UINT nHeight)
{
	m_nWidth = nWidth;
	m_nHeight = nHeight;
}

void CDisplayObject::SetWidth(UINT nWidth)
{
	m_nWidth = nWidth;
}

void CDisplayObject::SetHeight(UINT nHeight)
{
	m_nHeight = nHeight;
}

UINT CDisplayObject::GetWidth()
{
	return m_nWidth;
}

UINT CDisplayObject::GetHeight()
{
	return m_nHeight;
}

void CDisplayObject::SetAlpha(BYTE nAlpha)
{
	m_nAlpha = nAlpha;
}

BYTE CDisplayObject::GetAlpha()
{
	return m_nAlpha;
}

void CDisplayObject::SetShowFrame(BOOL bShowFrame)
{
	m_bShowFrame = bShowFrame;
}

BOOL CDisplayObject::GetShowFrame()
{
	return m_bShowFrame;
}

BOOL CDisplayObject::IsMouseOn(POINT ptMousePos)
{
	if (!m_bVisible)
	{
		return FALSE;
	}

	RECT rRect = {m_ptScreenPos.x,m_ptScreenPos.y,m_ptScreenPos.x+m_nWidth,m_ptScreenPos.y+m_nHeight};
	return PtInRect(&rRect,ptMousePos);
}

BOOL CDisplayObject::IsMouseOn(HWND hWnd)
{
	if (!m_bVisible)
	{
		return FALSE;
	}
	if (hWnd == NULL)
	{
		return FALSE;
	}

	POINT pt = {0,0};
	RECT rect = {m_ptScreenPos.x,m_ptScreenPos.y,m_ptScreenPos.x+m_nWidth,m_ptScreenPos.y+m_nHeight};
	GetCursorPos(&pt);
	ScreenToClient(hWnd,&pt);
	return PtInRect(&rect,pt);
}

BOOL CDisplayObject::IsMouseOn(int x,int y)
{
	if (!m_bVisible)
	{
		return FALSE;
	}

	RECT rRect = {m_ptScreenPos.x,m_ptScreenPos.y,m_ptScreenPos.x+m_nWidth,m_ptScreenPos.y+m_nHeight};
	POINT ptMousePos = {x,y};
	return PtInRect(&rRect,ptMousePos);
}

void CDisplayObject::DrawFrame(HDC hDC)
{
	if (m_bShowFrame && hDC != NULL)
	{
		HBRUSH hBrush;
		HBRUSH hBrushOld;

		HPEN hPen;
		HPEN hPenOld;

		hBrush = (HBRUSH)GetStockObject(NULL_BRUSH);
		hBrushOld = (HBRUSH)SelectObject(hDC,hBrush);

		hPen = (HPEN)CreatePen(PS_SOLID,2,0xFF0000);
		hPenOld = (HPEN)SelectObject(hDC,hPen);

		RoundRect(hDC,m_ptScreenPos.x - 1,m_ptScreenPos.y - 1,m_ptScreenPos.x + m_nWidth + 2,m_ptScreenPos.y + m_nHeight + 2,5,5);

		SelectObject(hDC,hPenOld);
		DeleteObject(hPen);

		SelectObject(hDC,hBrushOld);
		DeleteObject(hBrush);
	}
}